﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BackOffice.Web.Models;
using BackOffice.Web.WorkOrdersReference;
using WorkOrders.Domain.BLL;
using WorkOrders.Domain.Entities;

namespace BackOffice.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View(new CustomerManager().GetAllCustomers());
        }

        public ActionResult Create()
        {
            return View(new Customer());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(Customer customer)
        {
            new CustomerManager().SaveCustomer(customer);
            return RedirectToAction("Index");
        }

        public ActionResult Assign(int id)
        {
            return View(new WorkItemModel());
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Assign(WorkItemModel model)
        {
            var client = new WorkOrdersSeviceClient();
            client.AddWorkOrder(model.Id, model.Engineer);
            return RedirectToAction("Index");
        }
    }
}
